<?php
/**
 * @version 	$Id: fHtmlDocument.class.php 82 2010-03-17 08:45:39Z mylifeisskidrow@gmail.com $
 * @author 		$Author: mylifeisskidrow@gmail.com $
 * @copyright 	Copyright (c) 2010 Luu Trong Hieu. All right reserved.
 * @license 	GNU/GPL see license.php
 */

defined('IN_FLYWHEEL') or die('Restricted Access!');

/**
 * HTML Document
 * 
 * @package 	system
 * @subpackage 	document
 *
 */
class fHtmlDocument {
	public $title = _WEBSITE_NAME_;
	
	public $desciptions;
	
	public $keywork;
	
	public $meta;
	
	private $_baseUrl;
	
	private $_lang = 'vi-VN';
	
	private $_stylesheet = array();
	
	private $_javascript = array();
	
	private $_buffer;
	
	private $_blocks = array();
	
	public function __construct() {
		$this->_baseUrl = fFactory::getRouter()->getBaseUrl();				
	}
	
	/**
	 * Get Base Url
	 *
	 * @return string
	 */
	public function getBaseUrl() {
		return $this->_baseUrl;
	}
	
	/**
	 * Set buffer
	 * 	Set document include data
	 *
	 * @param string $content	data
	 * @param string $type		component|module
	 * @param string $name
	 * 
	 * @return void
	 */
	public function setBuffer($content, $type, $name = null) {
		if ($name != null) {			
			$this->_buffer[$type][$name] = $content;			
		}
		else {
			$this->_buffer[$type] = $content;
		}
	}
	
	/**
	 * Get Buffer
	 * 	get document include data
	 *
	 * @return array
	 */
	public function getBuffer() {
		return $this->_buffer;
	}
	
	public function setBlock($pos, $name, $param = null) {
		if (!isset($this->_blocks[$pos])) {
			$this->_blocks[$pos] = array();		
		}
		$this->_blocks[$pos][] = array ('name' => $name,'param' => $param); 
	}
	
	public function block($position) {
		if (!isset($this->_blocks[$position])) {
			return null;				
		}
		
		//fLoader::import('document.fModulesRender', 'systems', 'helper.php');
		$modules = $this->_blocks[$position];
		$html = '';
		for($i = 0, $size = sizeof($modules); $i < $size; ++$i) {
			$html .= fModulesRenderHelper::renderModule($modules[$i]['name'], $modules[$i]['param']);			
		}
		
		return $html;
	}
	
	public function getComponentData() {
		return $this->_buffer['component'];
	}
	
	/**
	 * Add Stylesheet
	 *
	 * @param string $file. Link to file
	 * @param array $media. Stylesheet Media style
	 */
	public function addStyleSheet($file, $media = array()) {
		$this->_stylesheet[$file] = $media;
	}
	
	public function addJavascript($file, $position = 'BOTTOM', $option = array()) {
		$this->_javascript[$position][$file] = $option;
	}
}